package com.zyh;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;

@WebServlet(urlPatterns = {"/student"})
public class StudentServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("get操作");
        resp.setContentType("text/html;charset=utf-8");
        resp.getWriter().write("<h1>天亮教育</h1>");
    }

    @Override
    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取请求信息，对请求进行必要的处理
        System.out.println(req.getHeader("Content-Type"));
        System.out.println(req.getParameter("age"));
//
//        // 也可以对数据进行响应
        resp.setStatus(200);
        resp.setContentType("application/json;charset=utf-8");
        resp.setCharacterEncoding("utf-8");
//        // 输出流，写输出的内容
        resp.getWriter().write("{\"name\":\"李四\"}");

    }
}
